using UnityEngine;

public class AfterImageFx : MonoBehaviour
{
    private SpriteRenderer sr;
    private float colorLooseRate;

    private void Awake()
    {
        sr = GetComponent<SpriteRenderer>();
    }

    private void Update()
    {
        float alpha = sr.color.a - colorLooseRate * Time.deltaTime;
        sr.color = new Color(sr.color.r, sr.color.g, sr.color.b, alpha);
        if (sr.color.a <= 0)
            Destroy(gameObject);
    }

    public void Setup(float loosingSpeed, Sprite image)
    {
        sr.sprite = image;
        colorLooseRate = loosingSpeed;
    }
}
